package com.dy.placeOrder.controller;

import com.dy.placeOrder.Comments;
import com.dy.placeOrder.service.CollectionService;
import com.dy.placeOrder.service.CommentsService;
import com.dy.placeOrder.util.SensitiveFilter;
import com.dy.placeOrder2.service.GoodsService;

import java.util.List;

import com.dy.placeOrder2.service.OrdersService;
import com.dy.pojo.Goods;
import com.dy.pojo.Orders;
import com.kaoshi.common.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("placeOrder/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private SensitiveFilter sensitiveFilter;

    @GetMapping("getCommentsByGid")
    public List<Comments> getCommentsByGid(Integer gid) {
        return commentsService.getCommentsByGid(gid);
    }

    @GetMapping("getGoodByGid")
    public Goods getGoodByGid(Integer gid) {
        return goodsService.getById(gid);
    }

    @PostMapping("add")
    public Result add(@RequestBody Comments comments) {
        commentsService.save(comments);
        return Result.ok();
    }

    // 修改评论点赞数
    @PostMapping("update")
    public Result update(@RequestBody Comments comments) {
        commentsService.updateById(comments);
        return Result.ok();
    }

    @PostMapping("filter")
    public Result filter(@RequestParam("str") String str) {
        return Result.ok(sensitiveFilter.filter(str));
    }
}